package com.wang.yupao.once;

import com.alibaba.excel.EasyExcel;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 导入星球数据
 */
@Slf4j
public class ImportXingQiuUser {
    public static void main(String[] args) {
        String fileName = "D:\\星球项目\\yupao\\yupao-backend\\src\\main\\resources\\test.xlsx";
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 同步读取会自动finish
        Gson gson = new Gson();
        List<XingQIuTableUserInfo> userInfoList = EasyExcel.read(fileName).head(XingQIuTableUserInfo.class).sheet().doReadSync();
        //去重
        System.out.println("总数: " + userInfoList.size());
        Map<String, List<XingQIuTableUserInfo>> listMap = userInfoList.stream().filter(userinfo -> StringUtils.isNotEmpty(userinfo.getName()))
                .collect(Collectors.groupingBy(XingQIuTableUserInfo::getName));

        System.out.println("不重复的昵称: " + listMap.keySet().size());
    }
}
